package com.hunk.utils.io;

import java.io.*;

/** Description:<br>
 * 	Utility for reading files in binary form.
 * @author Hunk
 * @since 2013-4-18
 */
public class BinaryFile {
	public static byte[] read(File bFile) throws IOException {
		BufferedInputStream bf = new BufferedInputStream(new FileInputStream(
				bFile));
		try {
			byte[] data = new byte[bf.available()];
			bf.read(data);
			return data;
		} finally {
			bf.close();
		}
	}

	public static byte[] read(String bFile) throws IOException {
		return read(new File(bFile).getAbsoluteFile());
	}

	public static void write(File file, byte[] mybyte) throws IOException,
			FileNotFoundException {
		OutputStream out = null;
		try {
			out = new FileOutputStream(file);
			out.write(mybyte);
			out.flush();
		} finally {
			if (out != null)
				out.close();
		}
	}

	public static void write(String file, byte[] mybyte) throws IOException,
			FileNotFoundException {
		write(new File(file), mybyte);
	}
}
